﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace SDFL.Utilities
{
    /// <summary>
    /// The factory of Log
    /// </summary>
    /// <history>
    ///     [Dylan]     2009-10-19      Created
    /// </history>
    public sealed class LogManager
    {
        private static System.Collections.ObjectModel.Collection<LogBase> m_logs = new System.Collections.ObjectModel.Collection<LogBase>();

        // this function interrup the structure of the library, 
        // but I want to use the TestLogs feature in a simple project;
        // so add this initializelogs function here, and just use the TextLog()
        public static LogCollection InitLogs()
        {
            LogCollection logColl = new LogCollection();
            logColl.Add(new SDFL.Utilities.TextLog());
            return logColl;
        }
        /// <summary>
        /// This function should only ever be called from one place: the base Log class's constructor.
        /// </summary>
        /// <param name="newLog">A log object to add to the m_logs collection</param>
        public static void AddLog(LogBase newLog)
        { 
            m_logs.Add(newLog);
        }

        private static  DateTime _groupStartTime;
        public static  DateTime GroupStartTime
        {
            get
            {
                return _groupStartTime;
            }
        }        

        public static void WriteEntry(EntryType entryType, string info)
        {
            foreach (LogBase log in m_logs)
            {
                log.WriteEntry(entryType, info);
            }            
        }

        public static void LogFailure(string info)
        {
            LogFailure(null, info, "");
        }

        public static void LogFailure(Exception ex)
        {
            LogFailure(ex, "", "");
        }

        public static void LogFailure(Exception ex, string info, string bugNumber)
        {
            foreach (LogBase log in m_logs)
            {
                log.LogFailure(ex, info, bugNumber);
            }            
        }

        public static void LogPass(string info)
        {
            foreach (LogBase log in m_logs)
            {
                log.LogPass(info);
            }
        }

        public static void LogPass()
        {
            foreach (LogBase log in m_logs)
            {
                log.LogPass();
            }
        }

        public static void InitSecnario(string scenarioDescription)
        {
            foreach (LogBase log in m_logs)
            {
                log.InitScenario(scenarioDescription);
            }
        }

        public static void InitTestCase(string testcaseDescription)
        {
            foreach (LogBase log in m_logs)
            {
                log.InitTestCase(testcaseDescription);
            }
        }

        
    }

    [Serializable()]
    public class LogCollection: System.Collections.ObjectModel.Collection<LogBase>
    {


    }
    
}
